#include <bits/stdc++.h>
using namespace std;

int m, n;

struct coordinate {
    int x, y;
};

const int MaxN = 100;
bool vis[MaxN][MaxN];
int dist[MaxN][MaxN];
coordinate path[MaxN][MaxN];

int xy[2][2] = {{1, 2}, {2, 1}};

bool judge(coordinate node) {
    if (node.x < 0 || node.x >= MaxN || node.y < 0 || node.y >= MaxN)
        return false;
    return true;
}

void bfs(coordinate start) {
    queue<coordinate> q;
    q.push(start);
    vis[start.x][start.y] = true;
    dist[start.x][start.y] = 0;
    
    path[start.x][start.y].x = -1;
    path[start.x][start.y].y = -1;
    
    while (!q.empty()) {
        coordinate last = q.front();
        q.pop();

        if (last.x == n && last.y == m) {
            return;
        }
        
        for (int i = 0; i < 2; i++) {
            coordinate next;
            next.x = last.x + xy[i][0];
            next.y = last.y + xy[i][1];
                
            if (vis[next.x][next.y])
                continue;
                
            if (judge(next)) {
                q.push(next);
                dist[next.x][next.y] = dist[last.x][last.y] + 1;
                vis[next.x][next.y] = true;
                path[next.x][next.y] = last;        
            }
        }    
    }    
}

void display(coordinate end) {
    cout << '(' << end.x << ',' << end.y << ')';
    while (end.x != 0 || end.y != 0) {
        cout << "<==" << '(' << path[end.x][end.y].x << ',' << path[end.x][end.y].y << ')';
        end = path[end.x][end.y];
    }
    cout << endl;
}

int main() {
    cin >> m >> n;  // m是列数，n是行数    
    coordinate s;
    memset(vis, 0, sizeof(vis));
    memset(dist, 0, sizeof(dist));
    s.x = 0;
    s.y = 0;
    bfs(s);
    cout << dist[n][m] << endl;
    coordinate end;
    end.x = n;
    end.y = m;
    // display(end); // 取消注释可显示路径
    return 0;
}